package com.bitauto.i.commonUtils.leet;

public class Answer26 {


    public int removeDuplicates(int[] nums) {
        int len = 1;
        for (int i = 0; i < nums.length - 1; i++) {
            while (i < nums.length - 1) {
                if (nums[i] == nums[i + 1]) {
                    i++;
                } else {
                    nums[len] = nums[i + 1];
                    len = len + 1;
                    break;
                }
            }
        }
        return len;
    }



    public int removeDuplicates2(int[] nums) {
        if (nums.length == 0) return 0;
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }


}
